import request from '@/utils/request'

// 获取医生工作台统计数据
export function getDoctorStats() {
  return request({
    url: '/api/doctor/consultation/stats',
    method: 'get'
  })
}

// 获取患者详情
export function getPatientDetail(patientId) {
  return request({
    url: `/api/doctor/patients/${patientId}/detail`,
    method: 'get'
  })
}

// 获取患者健康记录
export function getPatientHealthRecords(patientId) {
  return request({
    url: `/api/doctor/patient/${patientId}/records`,
    method: 'get'
  })
}

// 获取预约列表
export function getAppointmentList(params) {
  return request({
    url: '/api/doctor/appointments',
    method: 'get',
    params
  })
}

// 更新预约状态
export function updateAppointmentStatus(id, status) {
  return request({
    url: `/api/doctor/appointment/${id}/status`,
    method: 'put',
    params: { status }
  })
}

// 更新问诊状态
export function updateConsultationStatus(id, status) {
  return request({
    url: `/api/doctor/consultations/${id}/status`,
    method: 'put',
    params: { status }
  })
}

// 获取问诊详情
export function getConsultationDetail(id) {
  return request({
    url: `/api/consultations/detail/${id}`,
    method: 'get'
  })
}

// 结束问诊
export function endConsultation(id, remark) {
  return request({
    url: `/api/consultations/${id}/end`,
    method: 'put',
    params: { remark }
  })
}

// 修改密码
export function updatePassword(data) {
  return request({
    url: '/api/user/password',
    method: 'put',
    data
  })
}


// 更新服务状态
export function updateServiceStatus(online) {
  return request({
    url: '/api/doctor/service/status',
    method: 'put',
    params: { online }
  })
}

// 获取医生问诊列表
export function getConsultations(params) {
  return request({
    url: '/api/doctor/consultations',
    method: 'get',
    params
  })
}

// 接诊
export function acceptConsultation(id) {
  return request({
    url: `/api/consultations/${id}/accept`,
    method: 'put'
  })
}

// 拒绝问诊
export function rejectConsultation(id) {
  return request({
    url: `/api/consultations/${id}/reject`,
    method: 'put'
  })
}

// 发送问诊消息
export function sendConsultationMessage(data) {
  return request({
    url: '/api/consultations/message',
    method: 'post',
    data
  })
}

// 获取待处理问诊列表
export function getPendingConsultations() {
  return request({
    url: '/api/doctor/consultations',
    method: 'get',
    params: {
      status: 0,
      current: 1,
      size: 5
    }
  })
}


// 获取医生详情
export function getDoctorDetail(doctorId) {
  return request({
    url: `/api/doctor/info`,
    method: 'get',
    params: { doctorId }
  })
}

// 创建问诊
export function createConsultation(doctorId) {
  return request({
    url: '/api/consultations/create',
    method: 'post',
    data: { doctorId }
  })
}

// 获取医生列表
export function getDoctorList(params) {
  return request({
    url: '/api/doctor/list',
    method: 'get',
    params: {
      current: params.current,
      size: params.size,
      name: params.name
    }
  })
}

// 获取医生的患者列表
export function getPatientList(params) {
  return request({
    url: '/api/doctor/patients',
    method: 'get',
    params
  })
}

// 移除患者
export function removePatient(patientId) {
  return request({
    url: '/api/doctor/patient',
    method: 'delete',
    params: { patientId }
  })
}

// 更新患者信息
export function updatePatientInfo(patientId, data) {
  return request({
    url: `/api/doctor/patients/${patientId}/update`,
    method: 'post',
    data
  })
}
